<?php
/**
 * Created by PhpStorm.
 * User: bigniu
 * Date: 2020-01-25
 * Time: 15:56:29
 */

namespace app\admin\controller;


class Config extends Admin
{
    public function getList(){
        //配置信息获取
        $configs = Db("config")->select();
        $config = [];
        foreach ($configs as $key=>$item){
            if($item['name']=='confirmNumber'){
                $config[$item['name']]=unserialize($item['value']);
                continue;
            }
            $config[$item['name']]=$item['value'];
        }
        if(sizeof($config)==0){
            return error("暂无配置");
        }
        return success("成功",$config);
    }
    public function postAdd(){
        $name = input("name");
        $value = input("value");
        if($name==""){
            return error("请输入配置名");
        }
        if($value==""){
            return error("请输入配置值");
        }
        config($name,$value);
        return  success("添加成功");
    }
    public function postUpdate(){
        $config = input("config/a");
        if(!$config||sizeof($config)==0){
            return success("保存成功");
        }
        foreach($config as $key=>$value){
            if(is_array($value)){
                $value = serialize($value);
            }
            config($key,$value);
        }
        config("update_time",TIME);
        return success("保存成功");
    }

}